﻿#include "CScoketImpl.h"

struct SocketInfo
{
	char data[1024];
	int len;
};

//1.初始化；
void init_CSocketImplProtocol(void** handle)
{
	if (NULL == handle)
	{
		return;
	}

	struct SocketInfo* info = malloc(sizeof(struct SocketInfo));
	memset(info, 0, sizeof(struct SocketInfo));
	*handle = info;
}
//2.发送接口；
void send_CSocketImplProtocol(void* handle, unsigned char* sendData, int sendLen)
{
	if (NULL == handle)
	{
		return;
	}
	if (NULL == sendData)
	{
		return;
	}

	struct SocketInfo* info = (struct Socket*)handle;
	strncpy(info->data, sendData, sendLen);
	info->len = sendLen;
}
//3.接收接口；
void recv_CSocketImplProtocol(void* handle, unsigned char* recvData, int* recvLen)
{
	if (NULL == handle)
	{
		return;
	}
	if (NULL == recvData)
	{
		return;
	}
	if (NULL == recvLen)
	{
		return;
	}
	struct SocketInfo* info = (struct Socket*)handle;
	strncpy(recvData, info->data, info->len);
	*recvLen = info->len;
}
//4.关闭；
void close_CSocketImplProtocol(void* handle)
{
	if (NULL == handle)
	{
		return;
	}
	free(handle);
	handle = NULL;
}
